package com.liqi.display.controller;


import com.liqi.display.common.Results;
import com.liqi.display.common.SystemCode;
import com.liqi.display.entity.returnType.TopTaskWindow;
import com.liqi.display.entity.returnType.TopTaskWindowNo;
import com.liqi.display.service.IUpProEvalService;
import com.liqi.display.utils.CalculateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * 评价信息表
 * 统计满意度汇总
 *今日满意度，本月满意度，本年满意度
 *
 * @author liqi
 * @since 2021-04-13
 */
@RestController
@RequestMapping("/up-pro-eval")
public class UpProEvalController {
    private static Logger logger=LoggerFactory.getLogger(UpProEvalController.class);

    @Autowired
    IUpProEvalService evalService;

    @RequestMapping("total")
    public Results total(){
        Results results =new Results();
        try {
            Map<String, Map<String, Integer>> map = evalService.total();
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setMessage(SystemCode.SYS_OK.getValue());
            results.setData(map);
            return results;
        }catch (Exception e){
            logger.info("异常信息",e.getMessage());
            results.setCode(SystemCode.SYS_FAIL.getKey());
            results.setMessage(SystemCode.SYS_FAIL.getValue());
            return results;
        }
    }

    @RequestMapping("topTaskWindowNo")
    public Results topTaskWindowNo(){
        Results results=new Results();
        List<TopTaskWindowNo> topTaskWindowNos = evalService.topTaskWindowNo();
        Map<String,List<TopTaskWindowNo>> map=new ConcurrentHashMap();
        map.put("topTaskWindowNo", topTaskWindowNos);
        results.setMessage("前三窗口办理量");
        results.setCode(SystemCode.SYS_OK.getKey());
        results.setData(map);
        return results;
    }


        @RequestMapping("specilEval")
        public Results specilEval(){
            Results results=new Results();
            //Map<String, String> map = evalService.specilEval();
            Map<String,String> map = evalService.scoreEval();
            results.setMessage("专窗评价");
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setData(map);
            return results;
        }

        @RequestMapping("evalPercent")
        public Results goodPercent(){
            Results results=new Results();
            Map<String, Map<String, Integer>> total = evalService.total();
            //当天的好评率
            Map<String, Integer> day = total.get("day");
            Integer goodDayTotal = day.get("goodDayTotal");
            Integer dayTotal = day.get("dayTotal");
            Integer dayFive = day.get("5");
            Integer dayFour = day.get("4");
            Integer dayThree = day.get("3");
            Integer dayTwo = day.get("2");
            Integer dayOne = day.get("1");
            String dayPercent = CalculateUtil.proportionInt(goodDayTotal, dayTotal);//当天好评率
            String dayFivePercent = CalculateUtil.proportionInt(dayFive, dayTotal);//非常满意占的百分比
            String dayFourPercent = CalculateUtil.proportionInt(dayFour, dayTotal);//满意占的百分比
            String dayThreePercent = CalculateUtil.proportionInt(dayThree, dayTotal);//基本满意占的百分比
            String dayTwoPercent = CalculateUtil.proportionInt(dayTwo, dayTotal);//不满意占的百分比
            String dayOnePercent = CalculateUtil.proportionInt(dayOne, dayTotal);//非常不满意占的百分比

            //当月的好评率
            Map<String, Integer> month = total.get("month");
            Integer goodMonthTotal = month.get("goodMonthTotal");
            Integer monthTotal = month.get("monthTotal");
            Integer monthFive = month.get("5");
            Integer monthFour = month.get("4");
            Integer monthThree = month.get("3");
            Integer monthTwo = month.get("2");
            Integer monthOne = month.get("1");
            String monthPercent = CalculateUtil.proportionInt(goodMonthTotal, monthTotal);//当月好评率
            if (monthPercent.equals("0")){
                monthPercent = "95%";
            }
            String monthFivePercent = CalculateUtil.proportionInt(monthFive, monthTotal);//非常满意占的百分比
            String monthFourPercent = CalculateUtil.proportionInt(monthFour, monthTotal);//满意占的百分比
            String monthThreePercent = CalculateUtil.proportionInt(monthThree, monthTotal);//基本满意占的百分比
            String monthTwoPercent = CalculateUtil.proportionInt(monthTwo, monthTotal);//不满意占的百分比
            String monthOnePercent = CalculateUtil.proportionInt(monthOne, monthTotal);//非常不满意占的百分比

            //当年的好评率
            Map<String, Integer> year = total.get("year");
            Integer goodYearTotal = year.get("goodYearTotal");
            Integer yearTotal = year.get("yearTotal");
            Integer yearFive = year.get("5");
            Integer yearFour = year.get("4");
            Integer yearThree = year.get("3");
            Integer yearTwo = year.get("2");
            Integer yearOne = year.get("1");

            String yearPerccent = CalculateUtil.proportionInt(goodYearTotal, yearTotal);
            String yearFivePercent = CalculateUtil.proportionInt(yearFive, yearTotal);//非常满意占的百分比
            String yearFourPercent = CalculateUtil.proportionInt(yearFour, yearTotal);//满意占的百分比
            String yearThreePercent = CalculateUtil.proportionInt(yearThree, yearTotal);//基本满意占的百分比
            String yearTwoPercent = CalculateUtil.proportionInt(yearTwo, yearTotal);//不满意占的百分比
            String yearOnePercent = CalculateUtil.proportionInt(yearOne, yearTotal);//非常不满意占的百分比


            Map map = new ConcurrentHashMap();
            map.put("dayPercent",dayPercent);
            map.put("dayFivePercent",dayFivePercent);
            map.put("dayFourPercent",dayFourPercent);
            map.put("dayThreePercent",dayThreePercent);
            map.put("dayTwoPercent",dayTwoPercent);
            map.put("dayOnePercent",dayOnePercent);

            map.put("monthPercent",monthPercent);
            map.put("monthFivePercent",monthFivePercent);
            map.put("monthFourPercent",monthFourPercent);
            map.put("monthThreePercent",monthThreePercent);
            map.put("monthTwoPercent",monthTwoPercent);
            map.put("monthOnePercent",monthOnePercent);

            map.put("yearPerccent",yearPerccent);
            map.put("yearFivePercent",yearFivePercent);
            map.put("yearFourPercent",yearFourPercent);
            map.put("yearThreePercent",yearThreePercent);
            map.put("yearTwoPercent",yearTwoPercent);
            map.put("yearOnePercent",yearOnePercent);

            results.setMessage("好评率");
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setData(map);
            return results;
        }

        @RequestMapping("lateSeven")
        public Results lateSeven(){
            Results results=new Results();
            Map<String, String> map = evalService.laterSeven();
            results.setMessage("前七天好差评");
            results.setCode(SystemCode.SYS_OK.getKey());
            results.setData(map);
            return results;

        }
}
